<template>
    <div style="min-width:809px">
        <div v-if="$route.path == '/comeStorage'">
            <div class="vs-search-box">
                <el-form ref="form" :inline="true" :model="paging" label-width="120px">
                    <el-form-item label="商品名称：">
                        <el-input style="width:250px" v-model="paging.title"></el-input>
                    </el-form-item>
                    <el-form-item label="商品ID：">
                        <el-input style="width:250px" v-model="paging.goods_id"></el-input>
                    </el-form-item>
                    <el-form-item label="" class="vs-right-btns">
                        <el-button @click="reset">重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                    <el-form-item label="调动时间：">
                        <el-date-picker
                            style="width:250px"
                            v-model="paging.time"
                            type="date"
                            value-format="timestamp"
                            placeholder="选择日期">
                            </el-date-picker>
                    </el-form-item>
                    <el-form-item label="类型：" :inline="true" prop="username">
                        <el-select clearable v-model="paging.type" style="width:250px" placeholder="请选择">
                            <el-option label="退货出库" :value="1"> </el-option>
                            <el-option label="调拨出库" :value="2"> </el-option>
                        </el-select>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <div class="operation-box clear-float">
                    <!-- <div class="title-left"> 分销列表 </div> -->
                    <el-button class="left-auto" @click="utils.goUrl('/comeStorageInfo?type=2');"  type="primary">新增</el-button>
                </div>
                <el-table v-loading="loading" :data="tableData" header-row-class-name="has-gutter-table" style="width: 100%">
                    <el-table-column prop="goods_id" label="商品ID" > </el-table-column>
                    <el-table-column prop="goods.cate.title" label="商品品类" > </el-table-column>
                    <el-table-column prop="goods.title" label="商品名称" > </el-table-column>
                    <el-table-column label="商品规格" min-width="100">
                        <template slot-scope="scope">
                            {{scope.row.goods.sku.sku_text}}
                        </template>
                    </el-table-column>
                    <el-table-column  label="类型" min-width="80">
                        <template slot-scope="scope">
                            {{scope.row.type | deliveryType}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="stock" label="出库数量（件）" min-width="120">
                        <template slot-scope="scope" v-if="scope.row.wareSku">
                        {{scope.row.wareSku[0].stock}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="create_time" label="出库单价（元）" min-width="120">
                        <template slot-scope="scope">
                            {{scope.row.goods.sku.sale_price}}
                        </template>
                    </el-table-column>
                    <el-table-column label="库存数量（件）" >
                        <template slot-scope="scope">
                            {{scope.row.goods.sku.stock}}
                        </template>
                    </el-table-column>
                    <el-table-column prop="store.title" label="调入门店" > </el-table-column>
                    <el-table-column prop="remarks" label="备注" > </el-table-column>
                    <el-table-column prop="create_time" label="调动时间" min-width="130">
                        <template slot-scope="scope">
                        <span class="line-2">{{ scope.row.create_time }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column fixed="right" width="120" label="操作">
                        <template slot-scope="scope">
                            <span @click="setRow(1,scope.row)" class="tab-table-text">查看</span>
                            <span @click="setRow(3,scope.row)" class="tab-table-text">编辑</span>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="paging.page" :page-size="paging.limit" layout="sizes,prev, pager, next, jumper" :total="paging.total">
                    </el-pagination>
                </div>
            </div>
        </div>
        <router-view></router-view>
        <el-dialog title="分销记录" :visible.sync="isInfo">
            <!-- width="570px" -->
            <el-table :data="recordList" v-loading="loading2" header-row-class-name="has-gutter-table" style="width: 100%">
                <el-table-column prop="company.title" label="公司名称"> </el-table-column>
                <el-table-column prop="create_time" label="邀请时间"> </el-table-column>
            </el-table>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="isInfo = false">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    data() {
        return {
            recordList: [],
            loading: false,
            loading2: false,
            isBtn: false,
            isInfo: false,
            dialogVisible: false,
            paging: {
                title: '',//姓名
                goods_id: '',//开始时间
                time: '',//结束时间
                type:'',
                page: 1,
                total: 0,
                limit: 10,
            },

            form: {
                date: "",
            },
            tableData: []
        };
    },
    filters:{
        deliveryType(val){
            switch (val) {
                case 1:
                    val = '退货出库'
                    break;
                case 2:
                    val = '调拨出库'
                    break;
            }
            return val;
        }
    },
    created() {
        if (this.$route.path == '/comeStorage') {
            this.handleCurrentChange(1);
        }
    },
    methods: {
        async setRow(type, row) {
            if(type==2){
                this.$msgbox({
                    title: '提示',
                    message: '确定要删除该入库商品吗?',
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    beforeClose:async (action, instance, done) => {
                        if (action === 'confirm') {
                        instance.confirmButtonLoading = true;
                        instance.confirmButtonText = '执行中...';
                        let {code,data} = await this.$Http.delWarehousing({id:String(row.id)})
                            if(code){
                                this.$message.success('删除成功!');
                                this.handleCurrentChange(1)
                            }
                            done();
                            instance.confirmButtonLoading = false;
                        } else {
                            done();
                        }
                    }
                }).then(action => {

                }).catch(()=>{});
            }else{
               this.utils.goUrl(`/comeStorageInfo?type=${type}&id=${row.id}`);
            }
        },
        handleClose(dom) {
            this.$refs['ruleForm'].resetFields();
            this.dialogVisible = false;
            dom && dom();
        },
        async repairGetList() {
            this.loading = true;
             let obj = Object.assign({},this.paging)
            obj.time/=1000;
            let { code, data } = await this.$Http.getWarehouse(obj);
            this.loading = false;
            if (code) {
                this.tableData = data.data.map(v=>{
                    if(v.goods.sku.length){
                        v.goods.sku = v.goods.sku[0]
                    }
                    return v;
                });
                this.paging.total = data.total;
            }
        },
        reset() {//重置
            this.paging = this.$options.data().paging;
            this.form.date = '';
            this.handleCurrentChange(1)
        },
        handleSizeChange(val) {
            this.paging.limit = val;
            this.repairGetList()
        },
        handleCurrentChange(val) {
            this.paging.page = val;
            this.repairGetList()
        }
    },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
    width: 130px;
    height: 130px;
}
</style>